import {LOGIN,LOGOUT,LOGIN_SUCCESS,LOGIN_FAIL,BASICINFO} from '../constants/login'
import api from '../services/api'
import { parse_lrc } from '../utils/common'

export const login = ( cellphone, passwd) =>{
    //  return {
    //      type: LOGIN,payload,
    //      cellphone, passwd
    //  }
    return dispatch=>{
        api.get('/login/cellphone',{
            cellphone,passwd
        }).then((res)=>{
            const { code } = res.data
            let tip = '登录成功'
            if (code !== 200) {
              tip = res.data.msg || '登录失败'
              dispatch({
                  type:LOGIN_FAIL
              })
            } else if(code === 200){
                let userInfo=res.data
                let userId= res.data.account.id
                let loginStatus= code
                dispatch({
                    type: LOGIN_SUCCESS,
                    payload:{
                        cellphone, userInfo, userId,loginStatus
                    }
                })
            }
        })
    }
}

export const logout = () =>{
    return {
        type:LOGOUT
    }
}

export const setBasicInfo = (param) => {
    // console.log('222',param)
    return {
        type: BASICINFO,
        payload: param
    }
}
 